/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.bitmapfun.ui;

import org.apache.http.Header;
import org.json.JSONObject;

import com.example.android.bitmapfun.BaasioConfig;
import com.example.android.bitmapfun.BuildConfig;
import com.example.android.bitmapfun.model.FilesResponse;
import com.example.android.bitmapfun.model.base.Entity;
import com.example.android.bitmapfun.model.util.JacksonUtils;
import com.example.android.bitmapfun.provider.Images;
import com.example.android.bitmapfun.util.Utils;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

/**
 * Simple FragmentActivity to hold the main {@link ImageGridFragment} and not much else.
 */
public class ImageGridActivity extends FragmentActivity {
    private static final String TAG = "ImageGridActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (BuildConfig.DEBUG) {
            Utils.enableStrictMode();
        }
        
        super.onCreate(savedInstanceState);

        if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
            final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.add(android.R.id.content, new ImageGridFragment(), TAG);
            ft.commit();
        }
    }
    
    private final int MENU_TEST = 1;
    private final int MENU_QUIT = 2;
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	menu.add(0, MENU_TEST, 0, "TEST");
        //menu.add(0, MENU_QUIT, 0, "Quit");
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch (item.getItemId()) {
        case MENU_TEST:
        	//executeImageUrlGet();
            return true;
        /*case MENU_QUIT:
            return true;*/
        }
        return false;
    }
    
    
    /**
     * 이미지url목록 가져오기
     */
    /*private void executeImageUrlGet() {
    	
    	AsyncHttpClient client = new AsyncHttpClient();
    	client.get(BaasioConfig.API_BASE_URL + "/file", new JsonHttpResponseHandler() {
    		@Override
    		public void onSuccess(int statusCode, JSONObject response) {
    			Log.d("AAA", "11 statusCode " + statusCode);
    			Log.d("AAA", "response " + response);
    			
    			FilesResponse filesResponse = JacksonUtils.objectFromJson(response.toString(), FilesResponse.class);
    			Log.d("AAA", "getCount " + filesResponse.getCount());
    			for (Entity entity : filesResponse.getEntities()) {
    				Images.imageThumbUrls.add(BaasioConfig.getImageUrl(entity.getUuid()));
    			}
    		}
    		
    	});
    }*/
}
